const reason =[
    { txt: '退货理由一', active: false },
    { txt: '退货理由二', active: false },
    { txt: '退货理由三', active: false },
    { txt: '退货理由四', active: false }
]
// pages/mine/returned_goods/returned_goods.js
import { ossupload } from '../../../utils/ossupload.js';
import { handPic, error } from '../../../utils/util.js';
// import Api, {  } from '../../utils/api';

Page({
    data: {
        a:false,

        reasonTxt: '',       // 退货理由
        reason: reason,      // 退货理由列表 

        imgs: [],           // 评价图片列表
        showimgs: [],
        description: '',   // 退货描述

    },

    /** 退货理由描述*/
    reason_describe: function (e) {
        this.setData({ description: e.detail.value });
    },
    /** 退货理由 */
    choice_reason:function(e){
        let { reason } = this.data;
        const { idx } = e.currentTarget.dataset;

        reason.map((items) => {
            items.active = false;
        });
        reason[idx].active=true;
        this.setData({ reason: reason, reasonTxt: reason[idx].txt});
    },
    /** 提交 */
    submit: function () {
        const { reasonTxt, description } = this.data;
        if (!reasonTxt){
            wx.showToast({
                title: '请选择退货理由',
            })
        };

        if (!description) {
            wx.showToast({
                title: '说点什么吧',
            })
        };

        if (reasonTxt && description){
            wx.showLoading({ title: '提交中' });
            // Api.fetch(GET_TIME_BUY_GOODS_LIST, { tbid: id }, goods_list => {
            //     wx.hideLoading();
           
        // });
        }
    },
    /** 上传图片 */
    upimg: function () {
        const that = this;
        const { imgs, showimgs } = this.data;

        ossupload(function (key) {
            console.log(key)
            let url = handPic(key, 4);
            imgs.push(key);
            showimgs.push(url);
            that.setData(
                {
                    imgs: imgs,
                    showimgs: showimgs
                }
            )
        });
    },
    /** 删除图片 */
    del_upimg: function (e) {
        let { idx } = e.target.dataset;
        let { imgs, showimgs } = this.data;
        const that = this;

        wx.showModal({
            content: '确认删除图片',
            success: function (res) {
                if (res.confirm) {
                    imgs.splice(idx, 1);
                    showimgs.splice(idx, 1);
                    that.setData({
                        imgs: imgs,
                        showimgs: showimgs
                    });
                } else if (res.cancel) {

                }
            }
        });
    },

    onLoad: function (options) {
        wx.showLoading({ title: '加载中'});
        // Api.fetch(GET_TIME_BUY_GOODS_LIST, { tbid: id }, goods_list => {
        //     wx.hideLoading();
            setTimeout(_=>{
                // const that = this;  退货理由 reason
                const that = this;
                wx.hideLoading();
                this.setData({ reason: reason})
            },600)

        // });
    },
    /**  用户点击右上角分享 */
    onShareAppMessage: function () {
    
    }
})